<script>
    (() => {
        const startTime = '2022-07-31'
        const endTime = '2022-09-01'

        // 计算出多少周
        const weekNum = Math.ceil(
            (new Date(endTime) - new Date(startTime)) / 1000 / 60 / 60 / 24 / 7
        )
        // 计算出每周的开始结束日期
        const dateList = []
        new Array(weekNum).fill('').forEach((_, i) => {
            const startT = i === 0
                ? startTime
                : new Date(new Date(dateList[i - 1][1]).setDate(new Date(dateList[i - 1][1]).getDate() + 1))
            const endT = weekNum === i + 1
                ? endTime
                : new Date(new Date(startT).setDate(new Date(startT).getDate() + 6))
            dateList.push(
                [startT, endT].map(d => {
                    return new Date(d).toLocaleDateString().replace(/\//g, '-').split(/\/|-/).map(v => +v >= 10 ? v : (0 + (+v + ''))).join('-')
                })
            );
        })

        console.log('周 dateList', dateList)
    })();
</script>